package com.sunda.spmsoversea.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.sunda.spmsoversea.entity.OverseaOperateLog;
import com.sunda.spmsoversea.mapper.OverseaOperateLogMapper;
import com.sunda.spmsoversea.service.IOverseaOperateLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import static com.sunda.spmsoversea.constant.OverseaLogConstant.SPMS;

/**
 * <p>
 * 海外仓操作日志表 服务实现类
 * </p>
 *
 * @author Wayne
 * @since 2021-08-26
 */
@Service
public class OverseaOperateLogServiceImpl extends ServiceImpl<OverseaOperateLogMapper, OverseaOperateLog> implements IOverseaOperateLogService {

    @Override
    public void addOverseaOperateLog(String userId, String documentNumber, String logContent, String logContentEn, String logType) {
        OverseaOperateLog overseaOperateLog = new OverseaOperateLog();
        overseaOperateLog.setDocumentNumber(documentNumber);
        overseaOperateLog.setLogContent(logContent);
        overseaOperateLog.setLogContentEn(logContentEn);
        overseaOperateLog.setLogType(StringUtils.isEmpty(logType) ? SPMS : logType);
        overseaOperateLog.setUserId(userId);
        this.baseMapper.insert(overseaOperateLog);
    }

    @Override
    public void addOverseaOperateLog(String userId, String documentNumber, String logContent, String logContentEn, String logType, String requestParam, String returnedMessage, String remark) {
        OverseaOperateLog overseaOperateLog = new OverseaOperateLog();
        overseaOperateLog.setDocumentNumber(documentNumber);
        overseaOperateLog.setLogContent(logContent);
        overseaOperateLog.setLogContentEn(logContentEn);
        overseaOperateLog.setLogType(StringUtils.isEmpty(logType) ? SPMS : logType);
        if (StringUtils.isNotEmpty(requestParam)){
            overseaOperateLog.setRequestParam(requestParam);
        }
        if (StringUtils.isNotEmpty(returnedMessage)){
            overseaOperateLog.setReturnedMessage(returnedMessage);
        }
        if (StringUtils.isNotEmpty(remark)){
            overseaOperateLog.setRemark(remark);
        }
        overseaOperateLog.setUserId(userId);
        this.baseMapper.insert(overseaOperateLog);
    }

    @Override
    public List<Map<String, Object>> getByDocumentNumber(String documentNumber) {
        if (StringUtils.isEmpty(documentNumber)){
            return null;
        }
        return this.baseMapper.getByDocumentNumber(documentNumber);
    }
}
